package com.lc.big_event.controller;

import com.lc.big_event.pojo.Result;
import com.lc.big_event.untils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author liuchun
 */
@RestController
@RequestMapping("/upload")
public class FileUploadController {

    /**
     * 文件上传
     */
    @PostMapping
    public Result<String> upload(MultipartFile file) throws Exception {
        String fileName = file.getOriginalFilename();
        String newFileName = UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf("."));
        String url = AliOssUtil.uploadFile(newFileName,file.getInputStream());
        return Result.success(url);
    }
}
